package cn.com.surker.base.pump.service.impl;

import cn.com.surker.base.pump.dao.PumpTypeDao;
import cn.com.surker.base.pump.entity.PumpType;
import cn.com.surker.base.pump.service.PumpTypeService;
import cn.com.surker.enums.StateEnum;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.poi.util.StringUtil;
import org.springframework.cache.annotation.Cacheable;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 泵送类型表 基础实现
 * </p>
 *
 * @author admin
 * @since 2024-07-09
 */
public abstract class PumpTypeBaseImpl extends ServiceImpl<PumpTypeDao, PumpType> implements PumpTypeService {

	@Resource
	protected PumpTypeDao pumpTypeDao;

	@Cacheable(cacheNames = "pumpTypeCache")
	public List<PumpType> findAll() {
		QueryWrapper<PumpType> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("status", StateEnum.ENABLED.getCode());
		List<PumpType> pumpNormList = pumpTypeDao.selectList(queryWrapper);
		if (pumpNormList == null || pumpNormList.size() == 0)
			return null;
		return pumpNormList;
	}

	@Override
	public PumpType findByErpId(Long originId, Long erpId) {
		return pumpTypeDao.findByErpId(originId, erpId);
	}

	@Override
	@Cacheable(cacheNames = "pumpTypeCache", key = "#name == null ? 'NULL' : #name")
	public List<PumpType> findList(String name) {
		QueryWrapper<PumpType> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("status", StateEnum.ENABLED.getCode());
		if (StringUtils.isNotBlank(name)) {
			queryWrapper.like("name", name);
		}
		List<PumpType> pumpTypes = pumpTypeDao.selectList(queryWrapper);
		return pumpTypes;
	}

	@Override
	public List<PumpType> findBySaleCon(Long conId) {
		if (conId == null) {
			return null;
		}
		return pumpTypeDao.findBySaleCon(conId);
	}
}